/**
 * 接口枚举
 * @type {{}}
 */
 export const ApiEnum ={
  none    :0,//未知接口
  repInfo :1, //工单详情接口
}

import React, { Component } from 'react';
import { stringify } from 'qs';
import request from '@/utils/request';

const BaseHttpComonentHOC=WrappedComponent =>apiType=>{
    class BaseHttpComonent extends Component {
      constructor(props) {
        super(props)
        this.state = {
          apiType: apiType,
          // id: props.location.query.id,
          data: null
        }
      }

      startPost = (url, params) => {
        return request(url, {
          method: 'POST',
          body: {
            ...params,
            method: 'post',
          },
        });

      }

      /**
       * 获取服务器数据
       */
      fetchServerData = () => {

        switch (this.state.apiType) {
          case ApiEnum.none: {
            break
          }

          case ApiEnum.repInfo: {
            this.startPost('/web/repair/queryOne', {id:this.props.location.query.id})
              .then(data => {
                this.setState({ data: data.ret })
              })
              .catch(err => {
                this.setState({ data: null })
              })
            break
          }
        }

      }

      componentDidMount = () => {
        this.fetchServerData()
      }

      render() {
        const { data } = this.state
        if (!data) {
          return <div>查询失败...</div>
        }

        return (<WrappedComponent
          {...this.props}
          data={data}
        />)
      }
    }
    return BaseHttpComonent
}
export  default  BaseHttpComonentHOC

